package com.fishery.authority.entity;

import com.baomidou.mybatisplus.annotation.*;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;

/**
 * @author 白sa能
 * @className
 * @date Created in 8:42 PM 1/17/21
 * @package com.fishery.authority.entity
 * @Description
 */
public class UserDetailsImpl extends User implements UserDetails, Serializable {

    /**
     * 用户角色
     */
    private Collection<GrantedAuthority> authorities;

    public void setAuthorities(Collection<GrantedAuthority> authorities) {
        this.authorities = authorities;
    }

    public UserDetailsImpl() {

    }

    public UserDetailsImpl(User user) {
//        super(user.getId(), user.getUsername(), user.getUsernameStatus(), user.getPassword(), user.getBaseId(), user.getPhone(), user.getEmail(), user.getAvatar(), user.getBaseIdentity(), user.getGmtCreate(), user.getGmtModified(), 0, user.getVersion());
        this.id = user.getId();
        this.phone =user.getPhone();
        this.username=user.getUsername();
        this.password=user.getPassword();
        this.baseId= user.getBaseId();
        this.baseIdentity= user.getBaseIdentity();
    }

    @ApiModelProperty(value = "用户id")
    @TableId(value = "id", type = IdType.ID_WORKER_STR)
    private String id;

    @ApiModelProperty(value = "手机")
    private String phone;

    @ApiModelProperty(value = "用户名")
    private String username;

    @ApiModelProperty(value = "登录密码")
    private String password;

    @ApiModelProperty(value = "养殖基地Id")
    private String baseId;

    @ApiModelProperty(value = "养殖基地的身份")
    private Integer baseIdentity;

    @Override
    public String getId() {
        return id;
    }

    @Override
    public void setId(String id) {
        this.id = id;
    }

    @Override
    public String getPhone() {
        return phone;
    }

    @Override
    public void setPhone(String phone) {
        this.phone = phone;
    }

    @Override
    public void setUsername(String username) {
        this.username = username;
    }

    @Override
    public void setPassword(String password) {
        this.password = password;
    }

    @Override
    public String getBaseId() {
        return baseId;
    }

    @Override
    public void setBaseId(String baseId) {
        this.baseId = baseId;
    }

    @Override
    public Integer getBaseIdentity() {
        return baseIdentity;
    }

    @Override
    public void setBaseIdentity(Integer baseIdentity) {
        this.baseIdentity = baseIdentity;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return this.authorities;
    }

    @Override
    public String getPassword() {
        return password;
    }

    @Override
    public String getUsername() {
        return username;
    }

    //账号过期
    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    //账号锁定
    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    //提供证书
    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    //账号启用
    @Override
    public boolean isEnabled() {
        return true;
    }
}
